﻿/* AgileFx Version 2.0
 * An open-source framework for rapid development of applications and services using Microsoft.net
 * Developed by: AgileHead
 * Website: www.agilefx.org
 * This component is licensed under the terms of the Apache 2.0 License.
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Mvc.Html;
using AgileFx.MVC.FormValidation;
using System.Linq.Expressions;

namespace AgileFx.MVC.Controls
{
    public static partial class HtmlUtil
    {
        public static MvcHtmlString TextBox<TModel, TField>(this HtmlHelper htmlHelper, TModel model, Expression<Func<TModel, TField>> lambda)
        {
            var propertyName = GetPropertyName(lambda);
            var prop = typeof(TModel).GetProperty(propertyName);
            return htmlHelper.TextBox(propertyName, prop.GetValue(model, null));
        }

        public static MvcHtmlString TextBox(this HtmlHelper htmlHelper, string name, Validation validationInfo)
        {
            return htmlHelper.TextBox(name, null, GetValidationAttributes(validationInfo));
        }

        public static MvcHtmlString TextBox(this HtmlHelper htmlHelper, string name, object value, Validation validationInfo)
        {
            return htmlHelper.TextBox(name, value, GetValidationAttributes(validationInfo));
        }

        public static MvcHtmlString TextBox(this HtmlHelper htmlHelper, string name, object value, object htmlAttributes, Validation validationInfo)
        {
            return htmlHelper.TextBox(name, value, GetValidationAttributes(htmlAttributes, validationInfo));
        }
    }
}
